//
//  ZJKMainViewController.swift
//  MicroBlog
//
//  Created by VAD on 16/4/16.
//  Copyright © 2016年 朱江坤. All rights reserved.
//

import UIKit

class ZJKMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //点击加号按钮执行的闭包
        let composeButtonClickClosure = { [weak self] in
            print("加号按钮被点击了")
            
            let composeView = ZJKComposeView()
            
            composeView.show(self)
            
            
            
        }
        
        let tabBar = ZJKTabBar()
        
        tabBar.composeButtonClickClosure = composeButtonClickClosure
        
        setValue(tabBar, forKey: "tabBar")

        
        
        addChildViewController(ZJKHomeViewController(), title: "首页", imgNamed: "tabbar_home")
        
        addChildViewController(ZJKMessageViewController(), title: "消息", imgNamed: "tabbar_message_center")
        
        addChildViewController(ZJKDiscoverViewController(), title: "发现", imgNamed: "tabbar_discover")
        
        addChildViewController(ZJKProfileViewController(), title: "我", imgNamed: "tabbar_profile")
    }


    func addChildViewController(vc: UIViewController,title: String,imgNamed: String) {
        
        vc.title = title
        
        //设置默认图片
        vc.tabBarItem.image = UIImage(named: imgNamed)
        
        //设置选中时的图片
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgNamed)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置文字的颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: vc))
        
    }


}
